		TITLE	MODEND - Copyright (c) 1994 SLR Systems

		INCLUDE	MACROS
		INCLUDE	SYMBOLS
		INCLUDE	SEGMENTS
		INCLUDE	MODULES
		INCLUDE	FIXTEMPS

		PUBLIC	MODEND,MODEND32


		.DATA

		EXTERNDEF	REFERENCE_FLAGS:BYTE

		EXTERNDEF	END_OF_RECORD:DWORD,DEFAULT_SIZE:DWORD,MODEND_OWNER_GINDEX:DWORD,MODEND_ADDRESS:DWORD

		EXTERNDEF	MODULE_GARRAY:STD_PTR_S


		.CODE	PASS1_TEXT

		EXTERNDEF	PRELIM:PROC,MODEND_RETURN:PROC,OBJ_PHASE:PROC,FIXUPP_MODEND:PROC,STORE_OPTIMAL_MODEND:PROC
		EXTERNDEF	FIXUPP_STORE:PROC,WARN_ASCIZ_RET:PROC

		EXTERNDEF	DUP_MODEND_ERR:ABS

MODEND32:
		MOV	CL,MASK BIT_32
		JMP	MODEND_CONT

MODEND		PROC
		;
		;DS:SI IS RECORD
		;
		;HANDLE MOD_TYP AND OPTIONAL START ADDRESS
		;
if	fg_phar
		MOV	CL,BPTR DEFAULT_SIZE
else
		MOV	CL,0
endif

MODEND_CONT::
		MOV	AL,[ESI]
		INC	ESI

		ADD	ESP,4		;OLD RETURN ADDRESSES
		TEST	AL,40H		;IS THERE A STARTUP ADDRESS?

		MOV	EDX,END_OF_RECORD
		JNZ	MODEND_FIX	;YES, JUMP

		CMP	EDX,ESI
		JNZ	OBJ_E
MOD1:
		JMP	MODEND_RETURN

OBJ_E:
		CALL	OBJ_PHASE
		JMP	MOD1

MODEND_FIX:
		;
		;STORE LIKE FIXUPP
		;
		CMP	EDX,ESI
		JBE	OBJ_E
		;
		;IS THERE ALREADY A START ADDRESS?
		;
		MOV	EAX,MODEND_OWNER_GINDEX
		XOR	CH,CH

		TEST	EAX,EAX
		JNZ	MODEND_DUP

		MOV	AL,MASK S_HARD_REF
		RESS	LAST_DATA_COMDAT,CH

		MOV	REFERENCE_FLAGS,AL
		CALL	FIXUPP_MODEND

		JMP	MOD1

MODEND_DUP:
		BITT	IGNORE_DUP_STARTS
		JNZ	MOD1
		CONVERT	EAX,EAX,MODULE_GARRAY
		LEA	ECX,[EAX].MODULE_STRUCT._M_TEXT
		MOV	AL,DUP_MODEND_ERR
		CALL	WARN_ASCIZ_RET		;PHYSICAL NAME IN ECX
		JMP	MOD1

MODEND		ENDP


		END

